<?php
/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the  Academic Free License (AFL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to support@zprofess.com so we can send you a copy immediately.
 *
 * @category   	Prestashop module
 * @package		Easy Login
 * @version 	1.0
 * @author 		Kurosaki <kurosaki@zprofess.com>
 * @copyright   Copyright (c) 2012 ZPROFESS. (http://zprofess.com)
 * @license    	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

class zcreatemailController extends FrontController
{
	/**
	 * 
	 * @see override/classes/FrontController::run()
	 */
	public function run()
	{
		$this->init();
		$this->process();
	}
	
	/**
	 * 
	 * @see classes/FrontControllerCore::process()
	 */
	public function process()
	{
		if (Tools::isSubmit('SubmitCreate'))
		{
			$email = Tools::getValue('email');
			if (Customer::customerExists($email))
			{
				$this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.');
				unset($_GET['email']);
			}
			if (Tools::isSubmit('ajax'))
			{
				$return = array(
					'hasError' => !empty($this->errors),
					'errors' => $this->errors
				);
				die(Tools::jsonEncode($return));
			}
		}
		parent::preProcess();
	}
}